/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.pay.res;

import android.text.Editable;
import android.text.InputFilter;
import android.text.InputFilter.LengthFilter;
import android.text.TextWatcher;
import android.text.method.DigitsKeyListener;
import com.qihoo.gamecenter.sdk.common.view.CustEditText;

public class a {
    private static a a;

    public static a a() {
        if (a == null)
            a = new a();
        return a;
    }

    public void a(CustEditText paramCustEditText, int paramInt) {
        paramCustEditText.setKeyListener(DigitsKeyListener.getInstance("0123456789 "));
        paramCustEditText.setImeOptions(268435456);
        int i = paramInt / 4;
        int j = paramInt + ((paramInt % 4 == 0) ? i - 1 : i);
        paramCustEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(j) });
        paramCustEditText.a();
        paramCustEditText.b();
        paramCustEditText.addTextChangedListener(new TextWatcher(paramCustEditText) {
            private int c = 0;

            public void afterTextChanged(Editable paramEditable) {
                this.a.removeTextChangedListener(this);
                String str = a(paramEditable);
                int i = paramEditable.length();
                int j = str.length();
                int k = this.a.getSelectionStart();
                int l = 0;
                if (k == i)
                    l = j - i;
                else if ((k < i) && (k > 1))
                    if (this.c > 0)
                        if (this.c == 1)
                            for (int i1 = 0; i1 < this.c; ++i1) {
                                if (str.charAt(k - 1 - i1) != ' ')
                                    continue;
                                --l;
                            }
                        else if ((this.c > 1) && (k % 5 == 0))
                            l = -1;
                        else if (k % 5 == 0)
                            l = 1;
                this.a.setText(str);
                this.a.setSelection(k + l);
                this.a.a();
                this.a.b();
                this.a.addTextChangedListener(this);
            }

            public void beforeTextChanged(CharSequence paramCharSequence, int paramInt1, int paramInt2, int paramInt3) {
                this.c = paramInt2;
            }

            public void onTextChanged(CharSequence paramCharSequence, int paramInt1, int paramInt2, int paramInt3) {}

            private String a(CharSequence paramCharSequence) {
                StringBuilder localStringBuilder = new StringBuilder();
                int i = 0;
                for (int j = 0; j < paramCharSequence.length(); ++j) {
                    if (paramCharSequence.charAt(j) == ' ')
                        continue;
                    if ((i % 4 == 0) && (i > 0))
                        localStringBuilder.append(' ');
                    localStringBuilder.append(paramCharSequence.charAt(j));
                    ++i;
                }
                return localStringBuilder.toString();
            }
        });
    }
}